﻿import * as canTypes from './candidateTypes';

function getTitle(can) {
    if (can.tea) return can.tea.name;
    if (can.sec) return can.sec.name;
    if (can.dep) return can.dep.name;
    return '全校';
}
function getKey(can) {
    if (can.tea) return can.tea.eno;
    if (can.sec) return can.sec.dno;
    if (can.dep) return can.dep.dno;
    return 'all'
}
function getDep(can) {
    // if teacher is directly attached on college, 
    // the tea exists but dep not
    if ((can.tea || can.sec) && can.dep) return '(' + can.dep.name + ')';
    return null;
}
function getType(can) {
    if (can.tea) return canTypes.TEACHER;
    if (can.sec) return can.sec.grp ? canTypes.GROUP : canTypes.SECTION;
    if (can.dep) return can.dep.grp ? canTypes.GROUP : canTypes.DEPARTMENT;
    return canTypes.COLLEGE;
}
export default class Candidate {
    constructor(dep, sec, tea) {
        this.dep = dep;
        this.sec = sec;
        this.tea = tea;
    }
    get type() { return getType(this) }
    get title() { return getTitle(this) }
    get key() { return getKey(this) }
    get department() { return getDep(this) }
}